package com.micangcaihang.micang.view;

import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.micangcaihang.common.utils.Properties;
import com.micangcaihang.common.utils.StringUtils;
import com.micangcaihang.common.utils.ToastUtils;
import com.micangcaihang.micang.R;
import com.micangcaihang.micang.entity.MatesChooseListBean;
import com.micangcaihang.micang.entity.MatesEntity;
import com.micangcaihang.micang.entity.MatesRequest;
import com.micangcaihang.micang.entity.PickerEntity;
import com.micangcaihang.micang.view.mvp.contract.MatesContract;
import com.micangcaihang.micang.view.mvp.presenter.MatesPresenter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * <pre>
 *     author : Fandy
 *     e-mail : fandayongfly@gmail.com
 *     time   : 2017/8/8
 *     update : 2017/8/8
 *     desc   : MiCang
 *     version: 1.0
 * </pre>
 */
public class MatesLayout extends LinearLayout implements MatesContract.View {
    @BindView(R.id.tv_married_title)
    TextView mTvMarriedTitle;
    @BindView(R.id.et_married_customer_name)
    EditText mEtMarriedCustomerName;
    @BindView(R.id.tv_married_customer_sex)
    TextView mTvMarriedCustomerSex;
    @BindView(R.id.lly_married_customer_sex)
    LinearLayout mLlyMarriedCustomerSex;
    @BindView(R.id.tv_married_certificate_type)
    TextView mTvMarriedCertificateType;
    @BindView(R.id.lly_married_certificate_type)
    LinearLayout mLlyMarriedCertificateType;
    @BindView(R.id.et_married_certificate_number)
    EditText mEtMarriedCertificateNumber;
    @BindView(R.id.tv_married_peason_credit)
    TextView mTvMarriedPeasonCredit;
    @BindView(R.id.lly_married_peason_credit)
    LinearLayout mLlyMarriedPeasonCredit;
    @BindView(R.id.tv_married_peason_crediless)
    TextView mTvMarriedPeasonCrediless;
    @BindView(R.id.lly_married_peason_crediless)
    LinearLayout mLlyMarriedPeasonCrediless;
    @BindView(R.id.tv_married_peason_enforced)
    TextView mTvMarriedPeasonEnforced;
    @BindView(R.id.lly_married_peason_enforced)
    LinearLayout mLlyMarriedPeasonEnforced;
    @BindView(R.id.et_married_mobile_phone)
    EditText mEtMarriedMobilePhone;
    @BindView(R.id.lly_married)
    LinearLayout mLlyMarried;
    @BindView(R.id.tv_current_title)
    TextView mTvCurrentTitle;
    @BindView(R.id.et_current_customer_name)
    EditText mEtCurrentCustomerName;
    @BindView(R.id.tv_current_customer_sex)
    TextView mTvCurrentCustomerSex;
    @BindView(R.id.lly_current_customer_sex)
    LinearLayout mLlyCurrentCustomerSex;
    @BindView(R.id.tv_current_certificate_type)
    TextView mTvCurrentCertificateType;
    @BindView(R.id.lly_current_certificate_type)
    LinearLayout mLlyCurrentCertificateType;
    @BindView(R.id.et_current_certificate_number)
    EditText mEtCurrentCertificateNumber;
    @BindView(R.id.tv_current_peason_credit)
    TextView mTvCurrentPeasonCredit;
    @BindView(R.id.lly_current_peason_credit)
    LinearLayout mLlyCurrentPeasonCredit;
    @BindView(R.id.tv_current_peason_crediless)
    TextView mTvCurrentPeasonCrediless;
    @BindView(R.id.lly_current_peason_crediless)
    LinearLayout mLlyCurrentPeasonCrediless;
    @BindView(R.id.tv_current_peason_enforced)
    TextView mTvCurrentPeasonEnforced;
    @BindView(R.id.lly_current_peason_enforced)
    LinearLayout mLlyCurrentPeasonEnforced;
    @BindView(R.id.et_current_mobile_phone)
    EditText mEtCurrentMobilePhone;
    @BindView(R.id.lly_current)
    LinearLayout mLlyCurrent;
    @BindView(R.id.tv_predecessor_title)
    TextView mTvPredecessorTitle;
    @BindView(R.id.et_predecessor_customer_name)
    EditText mEtPredecessorCustomerName;
    @BindView(R.id.tv_predecessor_customer_sex)
    TextView mTvPredecessorCustomerSex;
    @BindView(R.id.lly_predecessor_customer_sex)
    LinearLayout mLlyPredecessorCustomerSex;
    @BindView(R.id.tv_predecessor_certificate_type)
    TextView mTvPredecessorCertificateType;
    @BindView(R.id.lly_predecessor_certificate_type)
    LinearLayout mLlyPredecessorCertificateType;
    @BindView(R.id.et_predecessor_certificate_number)
    EditText mEtPredecessorCertificateNumber;
    @BindView(R.id.tv_predecessor_peason_credit)
    TextView mTvPredecessorPeasonCredit;
    @BindView(R.id.lly_predecessor_peason_credit)
    LinearLayout mLlyPredecessorPeasonCredit;
    @BindView(R.id.tv_predecessor_peason_crediless)
    TextView mTvPredecessorPeasonCrediless;
    @BindView(R.id.lly_predecessor_peason_crediless)
    LinearLayout mLlyPredecessorPeasonCrediless;
    @BindView(R.id.tv_predecessor_peason_enforced)
    TextView mTvPredecessorPeasonEnforced;
    @BindView(R.id.lly_predecessor_peason_enforced)
    LinearLayout mLlyPredecessorPeasonEnforced;
    @BindView(R.id.et_predecessor_mobile_phone)
    EditText mEtPredecessorMobilePhone;
    @BindView(R.id.lly_predecessor)
    LinearLayout mLlyPredecessor;
    @BindView(R.id.lly_remarry)
    LinearLayout mLlyRemarry;
    @BindView(R.id.tv_divorced_title)
    TextView mTvDivorcedTitle;
    @BindView(R.id.et_divorced_customer_name)
    EditText mEtDivorcedCustomerName;
    @BindView(R.id.tv_divorced_customer_sex)
    TextView mTvDivorcedCustomerSex;
    @BindView(R.id.lly_divorced_customer_sex)
    LinearLayout mLlyDivorcedCustomerSex;
    @BindView(R.id.tv_divorced_certificate_type)
    TextView mTvDivorcedCertificateType;
    @BindView(R.id.lly_divorced_certificate_type)
    LinearLayout mLlyDivorcedCertificateType;
    @BindView(R.id.et_divorced_certificate_number)
    EditText mEtDivorcedCertificateNumber;
    @BindView(R.id.tv_divorced_peason_credit)
    TextView mTvDivorcedPeasonCredit;
    @BindView(R.id.lly_divorced_peason_credit)
    LinearLayout mLlyDivorcedPeasonCredit;
    @BindView(R.id.tv_divorced_peason_crediless)
    TextView mTvDivorcedPeasonCrediless;
    @BindView(R.id.lly_divorced_peason_crediless)
    LinearLayout mLlyDivorcedPeasonCrediless;
    @BindView(R.id.tv_divorced_peason_enforced)
    TextView mTvDivorcedPeasonEnforced;
    @BindView(R.id.lly_divorced_peason_enforced)
    LinearLayout mLlyDivorcedPeasonEnforced;
    @BindView(R.id.et_divorced_mobile_phone)
    EditText mEtDivorcedMobilePhone;
    @BindView(R.id.lly_divorced)
    LinearLayout mLlyDivorced;
    @BindView(R.id.tv_wid_title)
    TextView mTvWidTitle;
    @BindView(R.id.et_wid_customer_name)
    EditText mEtWidCustomerName;
    @BindView(R.id.tv_wid_customer_sex)
    TextView mTvWidCustomerSex;
    @BindView(R.id.lly_wid_customer_sex)
    LinearLayout mLlyWidCustomerSex;
    @BindView(R.id.tv_wid_certificate_type)
    TextView mTvWidCertificateType;
    @BindView(R.id.lly_wid_certificate_type)
    LinearLayout mLlyWidCertificateType;
    @BindView(R.id.et_wid_certificate_number)
    EditText mEtWidCertificateNumber;
    @BindView(R.id.tv_wid_death_certificate_type)
    TextView mTvWidDeathCertificateType;
    @BindView(R.id.lly_wid_death_certificate_type)
    LinearLayout mLlyWidDeathCertificateType;
    @BindView(R.id.lly_wid)
    LinearLayout mLlyWid;
    private int mType;
    private Context mContext;
    private View mView;
    private String titleType;
    private List<MatesEntity> mMatesEntities;
    private List<MatesRequest> mMatesRequests;
    private MatesRequest mMarriedCurrentRequest;
    private MatesRequest mRemarryCurrentRequest;
    private MatesRequest mRemarrypredecessorRequest;
    private MatesRequest mDivorcedRequest;
    private MatesRequest mWidRequest;
    private MatesPresenter mPresenter;
    private int pickerType;

    public MatesLayout(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        mContext = context;
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MatesTitle);
        int titleType = typedArray.getInteger(R.styleable.MatesTitle_titleType, 1);
        typedArray.recycle();
        switch (titleType) {
            case 1:
                this.titleType = "借款人";
                break;
            case 2:
                this.titleType = "共有人";
                break;
            case 3:
                this.titleType = "实际用款人";
                break;
            case 4:
                this.titleType = "共借人";
                break;
        }
        initView();
        mMatesEntities = new ArrayList<>();
        mMatesRequests = new ArrayList<>();

        mMarriedCurrentRequest = new MatesRequest("1");
        mRemarryCurrentRequest = new MatesRequest("1");
        mRemarrypredecessorRequest = new MatesRequest("2");
        mDivorcedRequest = new MatesRequest("1");
        mWidRequest = new MatesRequest("3");
        mPresenter = new MatesPresenter(this);
    }

    public int getType() {
        return mType;
    }

    public void setType(int type) {
        mType = type;
        switch (mType) {
            case 1:
                if (mMatesRequests.contains(mRemarryCurrentRequest)) {
                    mMatesRequests.remove(mRemarryCurrentRequest);
                }
                if (mMatesRequests.contains(mRemarrypredecessorRequest)) {
                    mMatesRequests.remove(mRemarrypredecessorRequest);
                }
                if (mMatesRequests.contains(mDivorcedRequest)) {
                    mMatesRequests.remove(mDivorcedRequest);
                }
                if (mMatesRequests.contains(mWidRequest)) {
                    mMatesRequests.remove(mWidRequest);
                }
                if (mMatesRequests.contains(mMarriedCurrentRequest)) {
                    mMatesRequests.remove(mMarriedCurrentRequest);
                }
                mLlyMarried.setVisibility(GONE);
                mLlyRemarry.setVisibility(GONE);
                mLlyDivorced.setVisibility(GONE);
                mLlyWid.setVisibility(GONE);
                break;
            case 2:
                if (mMatesRequests.contains(mRemarryCurrentRequest)) {
                    mMatesRequests.remove(mRemarryCurrentRequest);
                }
                if (mMatesRequests.contains(mRemarrypredecessorRequest)) {
                    mMatesRequests.remove(mRemarrypredecessorRequest);
                }
                if (mMatesRequests.contains(mDivorcedRequest)) {
                    mMatesRequests.remove(mDivorcedRequest);
                }
                if (mMatesRequests.contains(mWidRequest)) {
                    mMatesRequests.remove(mWidRequest);
                }
                if (!mMatesRequests.contains(mMarriedCurrentRequest)) {
                    mMatesRequests.add(mMarriedCurrentRequest);
                }
                mLlyMarried.setVisibility(VISIBLE);
                mLlyRemarry.setVisibility(GONE);
                mLlyDivorced.setVisibility(GONE);
                mLlyWid.setVisibility(GONE);
                break;
            case 3:
                if (!mMatesRequests.contains(mRemarryCurrentRequest)) {
                    mMatesRequests.add(mRemarryCurrentRequest);
                }
                if (!mMatesRequests.contains(mRemarrypredecessorRequest)) {
                    mMatesRequests.add(mRemarrypredecessorRequest);
                }
                if (mMatesRequests.contains(mDivorcedRequest)) {
                    mMatesRequests.remove(mDivorcedRequest);
                }
                if (mMatesRequests.contains(mWidRequest)) {
                    mMatesRequests.remove(mWidRequest);
                }
                if (mMatesRequests.contains(mMarriedCurrentRequest)) {
                    mMatesRequests.remove(mMarriedCurrentRequest);
                }
                mLlyMarried.setVisibility(GONE);
                mLlyRemarry.setVisibility(VISIBLE);
                mLlyDivorced.setVisibility(GONE);
                mLlyWid.setVisibility(GONE);
                break;
            case 4:
                if (mMatesRequests.contains(mRemarryCurrentRequest)) {
                    mMatesRequests.remove(mRemarryCurrentRequest);
                }
                if (mMatesRequests.contains(mRemarrypredecessorRequest)) {
                    mMatesRequests.remove(mRemarrypredecessorRequest);
                }
                if (!mMatesRequests.contains(mDivorcedRequest)) {
                    mMatesRequests.add(mDivorcedRequest);
                }
                if (mMatesRequests.contains(mWidRequest)) {
                    mMatesRequests.remove(mWidRequest);
                }
                if (mMatesRequests.contains(mMarriedCurrentRequest)) {
                    mMatesRequests.remove(mMarriedCurrentRequest);
                }
                mLlyMarried.setVisibility(GONE);
                mLlyRemarry.setVisibility(GONE);
                mLlyDivorced.setVisibility(VISIBLE);
                mLlyWid.setVisibility(GONE);
                break;
            case 5:
                if (mMatesRequests.contains(mRemarryCurrentRequest)) {
                    mMatesRequests.remove(mRemarryCurrentRequest);
                }
                if (mMatesRequests.contains(mRemarrypredecessorRequest)) {
                    mMatesRequests.remove(mRemarrypredecessorRequest);
                }
                if (mMatesRequests.contains(mDivorcedRequest)) {
                    mMatesRequests.remove(mDivorcedRequest);
                }
                if (!mMatesRequests.contains(mWidRequest)) {
                    mMatesRequests.add(mWidRequest);
                }
                if (mMatesRequests.contains(mMarriedCurrentRequest)) {
                    mMatesRequests.remove(mMarriedCurrentRequest);
                }
                mLlyMarried.setVisibility(GONE);
                mLlyRemarry.setVisibility(GONE);
                mLlyDivorced.setVisibility(GONE);
                mLlyWid.setVisibility(VISIBLE);
                break;
            default:
                if (mMatesRequests.contains(mRemarryCurrentRequest)) {
                    mMatesRequests.remove(mRemarryCurrentRequest);
                }
                if (mMatesRequests.contains(mRemarrypredecessorRequest)) {
                    mMatesRequests.remove(mRemarrypredecessorRequest);
                }
                if (mMatesRequests.contains(mDivorcedRequest)) {
                    mMatesRequests.remove(mDivorcedRequest);
                }
                if (mMatesRequests.contains(mWidRequest)) {
                    mMatesRequests.remove(mWidRequest);
                }
                if (mMatesRequests.contains(mMarriedCurrentRequest)) {
                    mMatesRequests.remove(mMarriedCurrentRequest);
                }
                mLlyMarried.setVisibility(GONE);
                mLlyRemarry.setVisibility(GONE);
                mLlyDivorced.setVisibility(GONE);
                mLlyWid.setVisibility(GONE);
                break;
        }
    }

    public List<MatesEntity> getMatesEntities() {
        return mMatesEntities;
    }

    public void setMatesEntities(List<MatesEntity> matesEntities) {
        mMatesEntities = matesEntities;
        setRequest(mMatesEntities);
    }

    private void setRequest(List<MatesEntity> matesEntities) {
        for (int i = 0; i < matesEntities.size(); i++) {
            MatesEntity matesEntity = matesEntities.get(i);
            String relationship_type = matesEntity.getRelationship_type();
            if ("1".equals(relationship_type)) {//现任
                switch (mType) {
                    case 2://已婚
                        String[] excludsArray = new String[]{"choose_list", "id"};
                        try {
                            Properties.copyPropertiesExclude(matesEntity, mMarriedCurrentRequest, excludsArray);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        //姓名
                        if (!StringUtils.isEmpty(matesEntity.getCustomer_name())) {
                            mEtMarriedCustomerName.setText(matesEntity.getCustomer_name());
                        }
                        //证件号码
                        if (!StringUtils.isEmpty(matesEntity.getCertificate_number())) {
                            mEtMarriedCertificateNumber.setText(matesEntity.getCertificate_number());
                        }
                        //证件号码
                        if (!StringUtils.isEmpty(matesEntity.getMobile_phone())) {
                            mEtMarriedMobilePhone.setText(matesEntity.getMobile_phone());
                        }
                        if (matesEntity.getChoose_list() != null) {
                            MatesChooseListBean choose_list = matesEntity.getChoose_list();
                            //性别
                            if (!StringUtils.isEmpty(choose_list.getCustomer_sex())) {
                                mTvMarriedCustomerSex.setText(choose_list.getCustomer_sex());
                            }
                            //证件类型
                            if (!StringUtils.isEmpty(choose_list.getCertificate_type())) {
                                mTvMarriedCertificateType.setText(choose_list.getCertificate_type());
                            }
                            //征信状况
                            if (!StringUtils.isEmpty(choose_list.getPeason_credit())) {
                                mTvMarriedPeasonCredit.setText(choose_list.getPeason_credit());
                            }
                            //是否失信
                            if (!StringUtils.isEmpty(choose_list.getPeason_crediless())) {
                                mTvMarriedPeasonCrediless.setText(choose_list.getPeason_crediless());
                            }
                            //是否被执行
                            if (!StringUtils.isEmpty(choose_list.getPeason_enforced())) {
                                mTvMarriedPeasonEnforced.setText(choose_list.getPeason_enforced());
                            }
                        }
                        if (!mMatesRequests.contains(mMarriedCurrentRequest))
                            mMatesRequests.add(mMarriedCurrentRequest);
                        break;
                    case 3://再婚
                        excludsArray = new String[]{"choose_list", "id"};
                        try {
                            Properties.copyPropertiesExclude(matesEntity, mRemarryCurrentRequest, excludsArray);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        //姓名
                        if (!StringUtils.isEmpty(matesEntity.getCustomer_name())) {
                            mEtCurrentCustomerName.setText(matesEntity.getCustomer_name());
                        }
                        //证件号码
                        if (!StringUtils.isEmpty(matesEntity.getCertificate_number())) {
                            mEtCurrentCertificateNumber.setText(matesEntity.getCertificate_number());
                        }
                        //证件号码
                        if (!StringUtils.isEmpty(matesEntity.getMobile_phone())) {
                            mEtCurrentMobilePhone.setText(matesEntity.getMobile_phone());
                        }
                        if (matesEntity.getChoose_list() != null) {
                            MatesChooseListBean choose_list = matesEntity.getChoose_list();
                            //性别
                            if (!StringUtils.isEmpty(choose_list.getCustomer_sex())) {
                                mTvCurrentCustomerSex.setText(choose_list.getCustomer_sex());
                            }
                            //证件类型
                            if (!StringUtils.isEmpty(choose_list.getCertificate_type())) {
                                mTvCurrentCertificateType.setText(choose_list.getCertificate_type());
                            }
                            //征信状况
                            if (!StringUtils.isEmpty(choose_list.getPeason_credit())) {
                                mTvCurrentPeasonCredit.setText(choose_list.getPeason_credit());
                            }
                            //是否失信
                            if (!StringUtils.isEmpty(choose_list.getPeason_crediless())) {
                                mTvCurrentPeasonCrediless.setText(choose_list.getPeason_crediless());
                            }
                            //是否被执行
                            if (!StringUtils.isEmpty(choose_list.getPeason_enforced())) {
                                mTvCurrentPeasonEnforced.setText(choose_list.getPeason_enforced());
                            }
                        }
                        if (!mMatesRequests.contains(mRemarryCurrentRequest))
                            mMatesRequests.add(mRemarryCurrentRequest);
                        break;
                    case 4://再婚
                        excludsArray = new String[]{"choose_list", "id"};
                        try {
                            Properties.copyPropertiesExclude(matesEntity, mDivorcedRequest, excludsArray);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        //姓名
                        if (!StringUtils.isEmpty(matesEntity.getCustomer_name())) {
                            mEtDivorcedCustomerName.setText(matesEntity.getCustomer_name());
                        }
                        //证件号码
                        if (!StringUtils.isEmpty(matesEntity.getCertificate_number())) {
                            mEtDivorcedCertificateNumber.setText(matesEntity.getCertificate_number());
                        }
                        //证件号码
                        if (!StringUtils.isEmpty(matesEntity.getMobile_phone())) {
                            mEtDivorcedMobilePhone.setText(matesEntity.getMobile_phone());
                        }
                        if (matesEntity.getChoose_list() != null) {
                            MatesChooseListBean choose_list = matesEntity.getChoose_list();
                            //性别
                            if (!StringUtils.isEmpty(choose_list.getCustomer_sex())) {
                                mTvDivorcedCustomerSex.setText(choose_list.getCustomer_sex());
                            }
                            //证件类型
                            if (!StringUtils.isEmpty(choose_list.getCertificate_type())) {
                                mTvDivorcedCertificateType.setText(choose_list.getCertificate_type());
                            }
                            //征信状况
                            if (!StringUtils.isEmpty(choose_list.getPeason_credit())) {
                                mTvDivorcedPeasonCredit.setText(choose_list.getPeason_credit());
                            }
                            //是否失信
                            if (!StringUtils.isEmpty(choose_list.getPeason_crediless())) {
                                mTvDivorcedPeasonCrediless.setText(choose_list.getPeason_crediless());
                            }
                            //是否被执行
                            if (!StringUtils.isEmpty(choose_list.getPeason_enforced())) {
                                mTvDivorcedPeasonEnforced.setText(choose_list.getPeason_enforced());
                            }
                        }
                        if (!mMatesRequests.contains(mDivorcedRequest))
                            mMatesRequests.add(mDivorcedRequest);
                        break;
                }
            } else if ("2".equals(relationship_type)) {//前任
                String[] excludsArray = new String[]{"choose_list", "id"};
                try {
                    Properties.copyPropertiesExclude(matesEntity, mRemarrypredecessorRequest, excludsArray);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                //姓名
                if (!StringUtils.isEmpty(matesEntity.getCustomer_name())) {
                    mEtPredecessorCustomerName.setText(matesEntity.getCustomer_name());
                }
                //证件号码
                if (!StringUtils.isEmpty(matesEntity.getCertificate_number())) {
                    mEtPredecessorCertificateNumber.setText(matesEntity.getCertificate_number());
                }
                //证件号码
                if (!StringUtils.isEmpty(matesEntity.getMobile_phone())) {
                    mEtPredecessorMobilePhone.setText(matesEntity.getMobile_phone());
                }
                if (matesEntity.getChoose_list() != null) {
                    MatesChooseListBean choose_list = matesEntity.getChoose_list();
                    //性别
                    if (!StringUtils.isEmpty(choose_list.getCustomer_sex())) {
                        mTvPredecessorCustomerSex.setText(choose_list.getCustomer_sex());
                    }
                    //证件类型
                    if (!StringUtils.isEmpty(choose_list.getCertificate_type())) {
                        mTvPredecessorCertificateType.setText(choose_list.getCertificate_type());
                    }
                    //征信状况
                    if (!StringUtils.isEmpty(choose_list.getPeason_credit())) {
                        mTvPredecessorPeasonCredit.setText(choose_list.getPeason_credit());
                    }
                    //是否失信
                    if (!StringUtils.isEmpty(choose_list.getPeason_crediless())) {
                        mTvPredecessorPeasonCrediless.setText(choose_list.getPeason_crediless());
                    }
                    //是否被执行
                    if (!StringUtils.isEmpty(choose_list.getPeason_enforced())) {
                        mTvPredecessorPeasonEnforced.setText(choose_list.getPeason_enforced());
                    }
                }
                if (!mMatesRequests.contains(mRemarrypredecessorRequest))
                    mMatesRequests.add(mRemarrypredecessorRequest);
            } else if ("3".equals(relationship_type)) {//配偶已逝世
                switch (mType) {
                    case 5:
                        String[] excludsArray = new String[]{"choose_list", "id"};
                        try {
                            Properties.copyPropertiesExclude(matesEntity, mWidRequest, excludsArray);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        //姓名
                        if (!StringUtils.isEmpty(matesEntity.getCustomer_name())) {
                            mEtWidCustomerName.setText(matesEntity.getCustomer_name());
                        }
                        //证件号码
                        if (!StringUtils.isEmpty(matesEntity.getCertificate_number())) {
                            mEtWidCertificateNumber.setText(matesEntity.getCertificate_number());
                        }
                        if (matesEntity.getChoose_list() != null) {
                            MatesChooseListBean choose_list = matesEntity.getChoose_list();
                            //性别
                            if (!StringUtils.isEmpty(choose_list.getCustomer_sex())) {
                                mTvPredecessorCustomerSex.setText(choose_list.getCustomer_sex());
                            }
                            //证件类型
                            if (!StringUtils.isEmpty(choose_list.getCertificate_type())) {
                                mTvPredecessorCertificateType.setText(choose_list.getCertificate_type());
                            }
                            //死亡证明
                            if (!StringUtils.isEmpty(choose_list.getDeath_certificate_type())) {
                                mTvWidDeathCertificateType.setText(choose_list.getDeath_certificate_type());
                            }

                        }
                        if (!mMatesRequests.contains(mWidRequest))
                            mMatesRequests.add(mWidRequest);
                        break;
                }
            }
        }
    }

    private void initView() {
        mView = LayoutInflater.from(mContext).inflate(R.layout.layout_mates, null);
        LayoutParams params = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        mView.setLayoutParams(params);
        addView(mView);
        ButterKnife.bind(this, mView);
        mTvMarriedTitle.setText(String.format(mContext.getString(R.string.format_married_title), titleType));
        mTvCurrentTitle.setText(String.format(mContext.getString(R.string.format_current_title), titleType));
        mTvPredecessorTitle.setText(String.format(mContext.getString(R.string.format_predecessor_title), titleType));
        mTvDivorcedTitle.setText(String.format(mContext.getString(R.string.format_divorced_title), titleType));
        mTvWidTitle.setText(String.format(mContext.getString(R.string.format_wid_title), titleType));
    }

    @OnClick({R.id.lly_married_customer_sex, R.id.lly_married_certificate_type, R.id.lly_married_peason_credit, R.id.lly_married_peason_crediless, R.id.lly_married_peason_enforced, R.id.lly_current_customer_sex, R.id.lly_current_certificate_type, R.id.lly_current_peason_credit, R.id.lly_current_peason_crediless, R.id.lly_current_peason_enforced, R.id.lly_predecessor_customer_sex, R.id.lly_predecessor_certificate_type, R.id.lly_predecessor_peason_credit, R.id.lly_predecessor_peason_crediless, R.id.lly_predecessor_peason_enforced, R.id.lly_predecessor, R.id.lly_divorced_customer_sex, R.id.lly_divorced_certificate_type, R.id.lly_divorced_peason_credit, R.id.lly_divorced_peason_crediless, R.id.lly_divorced_peason_enforced, R.id.lly_wid_customer_sex, R.id.lly_wid_certificate_type, R.id.lly_wid_death_certificate_type})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.lly_married_customer_sex:
                pickerType = 101;
                mPresenter.loadPickerViewData("sex_list", "性别");
                break;
            case R.id.lly_married_certificate_type:
                pickerType = 102;
                mPresenter.loadPickerViewData("certificate_type", "证件类型");
                break;
            case R.id.lly_married_peason_credit:
                pickerType = 103;
                mPresenter.loadPickerViewData("peason_credit", "征信状况");
                break;
            case R.id.lly_married_peason_crediless:
                pickerType = 104;
                mPresenter.loadPickerViewData("li_boolean", "是否失信");
                break;
            case R.id.lly_married_peason_enforced:
                pickerType = 105;
                mPresenter.loadPickerViewData("li_boolean", "是否被执行");
                break;
            case R.id.lly_current_customer_sex:
                pickerType = 201;
                mPresenter.loadPickerViewData("sex_list", "性别");
                break;
            case R.id.lly_current_certificate_type:
                pickerType = 202;
                mPresenter.loadPickerViewData("certificate_type", "证件类型");
                break;
            case R.id.lly_current_peason_credit:
                pickerType = 203;
                mPresenter.loadPickerViewData("peason_credit", "征信状况");
                break;
            case R.id.lly_current_peason_crediless:
                pickerType = 204;
                mPresenter.loadPickerViewData("li_boolean", "是否失信");
                break;
            case R.id.lly_current_peason_enforced:
                pickerType = 205;
                mPresenter.loadPickerViewData("li_boolean", "是否被执行");
                break;
            case R.id.lly_predecessor_customer_sex:
                pickerType = 301;
                mPresenter.loadPickerViewData("sex_list", "性别");
                break;
            case R.id.lly_predecessor_certificate_type:
                pickerType = 302;
                mPresenter.loadPickerViewData("certificate_type", "证件类型");
                break;
            case R.id.lly_predecessor_peason_credit:
                pickerType = 303;
                mPresenter.loadPickerViewData("peason_credit", "征信状况");
                break;
            case R.id.lly_predecessor_peason_crediless:
                pickerType = 304;
                mPresenter.loadPickerViewData("li_boolean", "是否失信");
                break;
            case R.id.lly_predecessor_peason_enforced:
                pickerType = 305;
                mPresenter.loadPickerViewData("li_boolean", "是否被执行");
                break;
            case R.id.lly_divorced_customer_sex:
                pickerType = 401;
                mPresenter.loadPickerViewData("sex_list", "性别");
                break;
            case R.id.lly_divorced_certificate_type:
                pickerType = 402;
                mPresenter.loadPickerViewData("certificate_type", "证件类型");
                break;
            case R.id.lly_divorced_peason_credit:
                pickerType = 403;
                mPresenter.loadPickerViewData("peason_credit", "征信状况");
                break;
            case R.id.lly_divorced_peason_crediless:
                pickerType = 404;
                mPresenter.loadPickerViewData("li_boolean", "是否失信");
                break;
            case R.id.lly_divorced_peason_enforced:
                pickerType = 405;
                mPresenter.loadPickerViewData("li_boolean", "是否被执行");
                break;
            case R.id.lly_wid_customer_sex:
                pickerType = 501;
                mPresenter.loadPickerViewData("sex_list", "性别");
                break;
            case R.id.lly_wid_certificate_type:
                pickerType = 502;
                mPresenter.loadPickerViewData("certificate_type", "证件类型");
                break;
            case R.id.lly_wid_death_certificate_type:
                pickerType = 503;
                mPresenter.loadPickerViewData("death_certificate_type", "死亡证明类型");
                break;
        }
    }


    /**
     * 针对Dilaog加载dialog加载弹窗
     *
     * @param title 提示文字
     */
    @Override
    public void showDialogLoading(String title) {

    }

    /**
     * 针对Dilaog隐藏加载dialiog
     */
    @Override
    public void hideDialogLoading() {

    }

    /**
     * Toast提示接口
     *
     * @param msg
     */
    @Override
    public void showTip(String msg) {
        ToastUtils.showShort(msg);
    }


    /**
     * 返回下拉框信息
     *
     * @param list
     * @param type
     */
    @Override
    public void returnPickerViewData(List<PickerEntity> list, String type) {
        switch (pickerType) {
            case 101:
                PickerViewHelper.showOnePickerView((Activity) mContext, type, mMarriedCurrentRequest.getCustomer_sex(), list,
                        pickerEntity1 -> {
                            mMarriedCurrentRequest.setCustomer_sex(pickerEntity1.getSign_id());
                            mTvMarriedCustomerSex.setText(pickerEntity1.getTitle());
                        });
                break;
            case 102:
                PickerViewHelper.showOnePickerView((Activity) mContext, type, mMarriedCurrentRequest.getCertificate_type(), list,
                        pickerEntity1 -> {
                            mMarriedCurrentRequest.setCertificate_type(pickerEntity1.getSign_id());
                            mTvMarriedCertificateType.setText(pickerEntity1.getTitle());
                        });
                break;
            case 103:
                PickerViewHelper.showOnePickerView((Activity) mContext, type, mMarriedCurrentRequest.getPeason_credit(), list,
                        pickerEntity1 -> {
                            mMarriedCurrentRequest.setPeason_credit(pickerEntity1.getSign_id());
                            mTvMarriedPeasonCredit.setText(pickerEntity1.getTitle());
                        });
                break;
            case 104:
                PickerViewHelper.showOnePickerView((Activity) mContext, type, mMarriedCurrentRequest.getPeason_crediless(), list,
                        pickerEntity1 -> {
                            mMarriedCurrentRequest.setPeason_crediless(pickerEntity1.getSign_id());
                            mTvMarriedPeasonCrediless.setText(pickerEntity1.getTitle());
                        });
                break;
            case 105:
                PickerViewHelper.showOnePickerView((Activity) mContext, type, mMarriedCurrentRequest.getPeason_enforced(), list,
                        pickerEntity1 -> {
                            mMarriedCurrentRequest.setPeason_enforced(pickerEntity1.getSign_id());
                            mTvMarriedPeasonEnforced.setText(pickerEntity1.getTitle());
                        });
                break;
            case 201:
                PickerViewHelper.showOnePickerView((Activity) mContext, type, mRemarryCurrentRequest.getCustomer_sex(), list,
                        pickerEntity1 -> {
                            mRemarryCurrentRequest.setCustomer_sex(pickerEntity1.getSign_id());
                            mTvCurrentCustomerSex.setText(pickerEntity1.getTitle());
                        });
                break;
            case 202:
                PickerViewHelper.showOnePickerView((Activity) mContext, type, mRemarryCurrentRequest.getCertificate_type(), list,
                        pickerEntity1 -> {
                            mRemarryCurrentRequest.setCertificate_type(pickerEntity1.getSign_id());
                            mTvCurrentCertificateType.setText(pickerEntity1.getTitle());
                        });
                break;
            case 203:
                PickerViewHelper.showOnePickerView((Activity) mContext, type, mRemarryCurrentRequest.getPeason_credit(), list,
                        pickerEntity1 -> {
                            mRemarryCurrentRequest.setPeason_credit(pickerEntity1.getSign_id());
                            mTvCurrentPeasonCredit.setText(pickerEntity1.getTitle());
                        });
                break;
            case 204:
                PickerViewHelper.showOnePickerView((Activity) mContext, type, mRemarryCurrentRequest.getPeason_crediless(), list,
                        pickerEntity1 -> {
                            mRemarryCurrentRequest.setPeason_crediless(pickerEntity1.getSign_id());
                            mTvCurrentPeasonCrediless.setText(pickerEntity1.getTitle());
                        });
                break;
            case 205:
                PickerViewHelper.showOnePickerView((Activity) mContext, type, mRemarryCurrentRequest.getPeason_enforced(), list,
                        pickerEntity1 -> {
                            mRemarryCurrentRequest.setPeason_enforced(pickerEntity1.getSign_id());
                            mTvCurrentPeasonEnforced.setText(pickerEntity1.getTitle());
                        });
                break;
            case 301:
                PickerViewHelper.showOnePickerView((Activity) mContext, type, mRemarrypredecessorRequest.getCustomer_sex(), list,
                        pickerEntity1 -> {
                            mRemarrypredecessorRequest.setCustomer_sex(pickerEntity1.getSign_id());
                            mTvPredecessorCustomerSex.setText(pickerEntity1.getTitle());
                        });
                break;
            case 302:
                PickerViewHelper.showOnePickerView((Activity) mContext, type, mRemarrypredecessorRequest.getCertificate_type(), list,
                        pickerEntity1 -> {
                            mRemarrypredecessorRequest.setCertificate_type(pickerEntity1.getSign_id());
                            mTvPredecessorCertificateType.setText(pickerEntity1.getTitle());
                        });
                break;
            case 303:
                PickerViewHelper.showOnePickerView((Activity) mContext, type, mRemarrypredecessorRequest.getPeason_credit(), list,
                        pickerEntity1 -> {
                            mRemarrypredecessorRequest.setPeason_credit(pickerEntity1.getSign_id());
                            mTvPredecessorPeasonCredit.setText(pickerEntity1.getTitle());
                        });
                break;
            case 304:
                PickerViewHelper.showOnePickerView((Activity) mContext, type, mRemarrypredecessorRequest.getPeason_crediless(), list,
                        pickerEntity1 -> {
                            mRemarrypredecessorRequest.setPeason_crediless(pickerEntity1.getSign_id());
                            mTvPredecessorPeasonCrediless.setText(pickerEntity1.getTitle());
                        });
                break;
            case 305:
                PickerViewHelper.showOnePickerView((Activity) mContext, type, mRemarrypredecessorRequest.getPeason_enforced(), list,
                        pickerEntity1 -> {
                            mRemarrypredecessorRequest.setPeason_enforced(pickerEntity1.getSign_id());
                            mTvPredecessorPeasonEnforced.setText(pickerEntity1.getTitle());
                        });
                break;
            case 401:
                PickerViewHelper.showOnePickerView((Activity) mContext, type, mDivorcedRequest.getCustomer_sex(), list,
                        pickerEntity1 -> {
                            mDivorcedRequest.setCustomer_sex(pickerEntity1.getSign_id());
                            mTvDivorcedCustomerSex.setText(pickerEntity1.getTitle());
                        });
                break;
            case 402:
                PickerViewHelper.showOnePickerView((Activity) mContext, type, mDivorcedRequest.getCertificate_type(), list,
                        pickerEntity1 -> {
                            mDivorcedRequest.setCertificate_type(pickerEntity1.getSign_id());
                            mTvDivorcedCertificateType.setText(pickerEntity1.getTitle());
                        });
                break;
            case 403:
                PickerViewHelper.showOnePickerView((Activity) mContext, type, mDivorcedRequest.getPeason_credit(), list,
                        pickerEntity1 -> {
                            mDivorcedRequest.setPeason_credit(pickerEntity1.getSign_id());
                            mTvDivorcedPeasonCredit.setText(pickerEntity1.getTitle());
                        });
                break;
            case 404:
                PickerViewHelper.showOnePickerView((Activity) mContext, type, mDivorcedRequest.getPeason_crediless(), list,
                        pickerEntity1 -> {
                            mDivorcedRequest.setPeason_crediless(pickerEntity1.getSign_id());
                            mTvDivorcedPeasonCrediless.setText(pickerEntity1.getTitle());
                        });
                break;
            case 405:
                PickerViewHelper.showOnePickerView((Activity) mContext, type, mDivorcedRequest.getPeason_enforced(), list,
                        pickerEntity1 -> {
                            mDivorcedRequest.setPeason_enforced(pickerEntity1.getSign_id());
                            mTvDivorcedPeasonEnforced.setText(pickerEntity1.getTitle());
                        });
                break;
            case 501:
                PickerViewHelper.showOnePickerView((Activity) mContext, type, mWidRequest.getCustomer_sex(), list,
                        pickerEntity1 -> {
                            mWidRequest.setCustomer_sex(pickerEntity1.getSign_id());
                            mTvWidCustomerSex.setText(pickerEntity1.getTitle());
                        });
                break;
            case 502:
                PickerViewHelper.showOnePickerView((Activity) mContext, type, mWidRequest.getCertificate_type(), list,
                        pickerEntity1 -> {
                            mWidRequest.setCertificate_type(pickerEntity1.getSign_id());
                            mTvWidCertificateType.setText(pickerEntity1.getTitle());
                        });
                break;
            case 503:
                PickerViewHelper.showOnePickerView((Activity) mContext, type, mWidRequest.getDeath_certificate_type(), list,
                        pickerEntity1 -> {
                            mWidRequest.setDeath_certificate_type(pickerEntity1.getSign_id());
                            mTvWidDeathCertificateType.setText(pickerEntity1.getTitle());
                        });
                break;
        }
    }

    public List<MatesRequest> getMatesRequests() {
        mMarriedCurrentRequest.setCustomer_name(mEtMarriedCustomerName.getText().toString().trim());
        mMarriedCurrentRequest.setCertificate_number(mEtMarriedCertificateNumber.getText().toString().trim());
        mMarriedCurrentRequest.setMobile_phone(mEtMarriedMobilePhone.getText().toString().trim());

        mRemarryCurrentRequest.setCustomer_name(mEtCurrentCustomerName.getText().toString().trim());
        mRemarryCurrentRequest.setCertificate_number(mEtCurrentCertificateNumber.getText().toString().trim());
        mRemarryCurrentRequest.setMobile_phone(mEtCurrentMobilePhone.getText().toString().trim());

        mRemarrypredecessorRequest.setCustomer_name(mEtPredecessorCustomerName.getText().toString().trim());
        mRemarrypredecessorRequest.setCertificate_number(mEtPredecessorCertificateNumber.getText().toString().trim());
        mRemarrypredecessorRequest.setMobile_phone(mEtPredecessorMobilePhone.getText().toString().trim());

        mDivorcedRequest.setCustomer_name(mEtDivorcedCustomerName.getText().toString().trim());
        mDivorcedRequest.setCertificate_number(mEtDivorcedCertificateNumber.getText().toString().trim());
        mDivorcedRequest.setMobile_phone(mEtDivorcedMobilePhone.getText().toString().trim());

        mWidRequest.setCustomer_name(mEtWidCustomerName.getText().toString().trim());
        mWidRequest.setCertificate_number(mEtWidCertificateNumber.getText().toString().trim());
        switch (mType) {
            case 1:
                if (mMatesRequests.contains(mRemarryCurrentRequest)) {
                    mMatesRequests.remove(mRemarryCurrentRequest);
                }
                if (mMatesRequests.contains(mRemarrypredecessorRequest)) {
                    mMatesRequests.remove(mRemarryCurrentRequest);
                }
                if (mMatesRequests.contains(mDivorcedRequest)) {
                    mMatesRequests.remove(mDivorcedRequest);
                }
                if (mMatesRequests.contains(mWidRequest)) {
                    mMatesRequests.remove(mWidRequest);
                }
                if (mMatesRequests.contains(mMarriedCurrentRequest)) {
                    mMatesRequests.remove(mMarriedCurrentRequest);
                }
                break;
            case 2:
                if (mMatesRequests.contains(mRemarryCurrentRequest)) {
                    mMatesRequests.remove(mRemarryCurrentRequest);
                }
                if (mMatesRequests.contains(mRemarrypredecessorRequest)) {
                    mMatesRequests.remove(mRemarryCurrentRequest);
                }
                if (mMatesRequests.contains(mDivorcedRequest)) {
                    mMatesRequests.remove(mDivorcedRequest);
                }
                if (mMatesRequests.contains(mWidRequest)) {
                    mMatesRequests.remove(mWidRequest);
                }
                if (!mMatesRequests.contains(mMarriedCurrentRequest)) {
                    mMatesRequests.add(mMarriedCurrentRequest);
                }
                break;
            case 3:
                if (!mMatesRequests.contains(mRemarryCurrentRequest)) {
                    mMatesRequests.add(mRemarryCurrentRequest);
                }
                if (!mMatesRequests.contains(mRemarrypredecessorRequest)) {
                    mMatesRequests.add(mRemarryCurrentRequest);
                }
                if (mMatesRequests.contains(mDivorcedRequest)) {
                    mMatesRequests.remove(mDivorcedRequest);
                }
                if (mMatesRequests.contains(mWidRequest)) {
                    mMatesRequests.remove(mWidRequest);
                }
                if (mMatesRequests.contains(mMarriedCurrentRequest)) {
                    mMatesRequests.remove(mMarriedCurrentRequest);
                }
                break;
            case 4:
                if (mMatesRequests.contains(mRemarryCurrentRequest)) {
                    mMatesRequests.remove(mRemarryCurrentRequest);
                }
                if (mMatesRequests.contains(mRemarrypredecessorRequest)) {
                    mMatesRequests.remove(mRemarryCurrentRequest);
                }
                if (!mMatesRequests.contains(mDivorcedRequest)) {
                    mMatesRequests.add(mDivorcedRequest);
                }
                if (mMatesRequests.contains(mWidRequest)) {
                    mMatesRequests.remove(mWidRequest);
                }
                if (mMatesRequests.contains(mMarriedCurrentRequest)) {
                    mMatesRequests.remove(mMarriedCurrentRequest);
                }
                break;
            case 5:
                if (mMatesRequests.contains(mRemarryCurrentRequest)) {
                    mMatesRequests.remove(mRemarryCurrentRequest);
                }
                if (mMatesRequests.contains(mRemarrypredecessorRequest)) {
                    mMatesRequests.remove(mRemarryCurrentRequest);
                }
                if (mMatesRequests.contains(mDivorcedRequest)) {
                    mMatesRequests.remove(mDivorcedRequest);
                }
                if (!mMatesRequests.contains(mWidRequest)) {
                    mMatesRequests.add(mWidRequest);
                }
                if (mMatesRequests.contains(mMarriedCurrentRequest)) {
                    mMatesRequests.remove(mMarriedCurrentRequest);
                }
                break;
            default:
                if (mMatesRequests.contains(mRemarryCurrentRequest)) {
                    mMatesRequests.remove(mRemarryCurrentRequest);
                }
                if (mMatesRequests.contains(mRemarrypredecessorRequest)) {
                    mMatesRequests.remove(mRemarryCurrentRequest);
                }
                if (mMatesRequests.contains(mDivorcedRequest)) {
                    mMatesRequests.remove(mDivorcedRequest);
                }
                if (mMatesRequests.contains(mWidRequest)) {
                    mMatesRequests.remove(mWidRequest);
                }
                if (mMatesRequests.contains(mMarriedCurrentRequest)) {
                    mMatesRequests.remove(mMarriedCurrentRequest);
                }
                break;
        }
        return mMatesRequests;
    }

    public void destroy() {
        mPresenter.onDetached();
    }
}
